ifeq ($(HOST_OS),Win32)
ENCRYPT := "$($(HOST_MCU_FAMILY)_LOCATION)/encrypt_win.exe"
DD_CMD  = $(PYTHON) "$($(HOST_MCU_FAMILY)_LOCATION)/padzero.py" $(BIN_OUTPUT_FILE) 28 $(PAD_BIN_OUTPUT_FILE)
CAT_CMD = $(ECHO)
else ifeq ($(HOST_OS),Linux32)
ENCRYPT := "$($(HOST_MCU_FAMILY)_LOCATION)/encrypt_linux"
DD_CMD  = dd if=/dev/zero of=$(TMP_BIN_OUTPUT_FILE) bs=28 count=1
CAT_CMD = cat $(TMP_BIN_OUTPUT_FILE) $(BIN_OUTPUT_FILE) > $(PAD_BIN_OUTPUT_FILE)
else ifeq ($(HOST_OS),Linux64)
ENCRYPT := "$($(HOST_MCU_FAMILY)_LOCATION)/encrypt_linux"
DD_CMD  = dd if=/dev/zero of=$(TMP_BIN_OUTPUT_FILE) bs=28 count=1
CAT_CMD = cat $(TMP_BIN_OUTPUT_FILE) $(BIN_OUTPUT_FILE) > $(PAD_BIN_OUTPUT_FILE)
else ifeq ($(HOST_OS),OSX)
ENCRYPT := "$($(HOST_MCU_FAMILY)_LOCATION)/encrypt_osx"
DD_CMD  = dd if=/dev/zero of=$(TMP_BIN_OUTPUT_FILE) bs=28 count=1
CAT_CMD = cat $(TMP_BIN_OUTPUT_FILE) $(BIN_OUTPUT_FILE) > $(PAD_BIN_OUTPUT_FILE)
else
$(error not surport for $(HOST_OS))
endif

CRC_BIN_OUTPUT_FILE :=$(LINK_OUTPUT_FILE:$(LINK_OUTPUT_SUFFIX)=_crc$(BIN_OUTPUT_SUFFIX))
TMP_BIN_OUTPUT_FILE := $(LINK_OUTPUT_FILE:$(LINK_OUTPUT_SUFFIX)=.tmp$(BIN_OUTPUT_SUFFIX))
PAD_BIN_OUTPUT_FILE := $(LINK_OUTPUT_FILE:$(LINK_OUTPUT_SUFFIX)=.pad0$(BIN_OUTPUT_SUFFIX))

ifeq ($(AOS_2NDBOOT_SUPPORT), yes)
EXTRA_POST_BUILD_TARGETS += gen_2ndboot_images
else
EXTRA_POST_BUILD_TARGETS += gen_standard_images
endif

gen_standard_images:
	$(eval OUT_MSG := $(shell $(ENCRYPT) $(BIN_OUTPUT_FILE) 0 0 0 0))
	$(QUIET)$(CP) $(CRC_BIN_OUTPUT_FILE) $(BIN_OUTPUT_FILE)
	$(QUIET)$(RM) -f $(CRC_BIN_OUTPUT_FILE)
	$(DD_CMD)
	$(CAT_CMD)
	$(QUIET)$(CP) $(PAD_BIN_OUTPUT_FILE) $(BIN_OUTPUT_FILE)
	$(QUIET)$(RM) -f $(TMP_BIN_OUTPUT_FILE)
	$(QUIET)$(RM) -f $(PAD_BIN_OUTPUT_FILE)

BOOT_OFFSET      := 0x0
APP_OFFSET       := 0x8E00   #0x1C000 - 0x13200
GEN_BIN_OUTPUT_FILE:= $(SCRIPTS_PATH)/gen_common_bin_output_file.py

BOOT_BIN_OUTPUT_FILE := $(OUTPUT_DIR)/binary/$(PLATFORM).2ndboot.bin
OTA_APP_BIN_OUTPUT_FILE := $(BIN_OUTPUT_FILE:.2ndboot.bin=_ota.bin)
APP_BIN_OUTPUT_FILE := $(BIN_OUTPUT_FILE:.2ndboot.bin=.bin)
ALL_BIN_OUTPUT_FILE := $(BIN_OUTPUT_FILE:.2ndboot.bin=.all.bin)

gen_2ndboot_images:
	$(eval OUT_MSG := $(shell $(ENCRYPT) $(BIN_OUTPUT_FILE) 0 0 0 0))
	$(QUIET)$(CP) $(CRC_BIN_OUTPUT_FILE) $(BOOT_BIN_OUTPUT_FILE)
	$(PYTHON) $(GEN_BIN_OUTPUT_FILE) -o $(ALL_BIN_OUTPUT_FILE) -f $(BOOT_OFFSET) $(BOOT_BIN_OUTPUT_FILE)
	$(PYTHON) $(GEN_BIN_OUTPUT_FILE) -o $(ALL_BIN_OUTPUT_FILE) -f $(APP_OFFSET) $(OTA_APP_BIN_OUTPUT_FILE)
	$(QUIET)$(CP) $(ALL_BIN_OUTPUT_FILE) $(APP_BIN_OUTPUT_FILE)
	$(QUIET)$(RM) -f $(ALL_BIN_OUTPUT_FILE)

